const app = getApp();
var api = require('../../../api.js');

Page({
  data: {
    nowtab: -1,
    list: [],
  },
  onLoad: function (options) {

    app.bind();
    this.getOrderMine();
  },
  onReady: function () {
  
  },
  onShow: function () {
  
  },
  onHide: function () {
    var url = app.getcurrentPage();
    wx.setStorageSync("from_url", url);
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {

    app.bind();
    this.getOrderMine();
    
    // 显示顶部刷新图标  
    wx.showNavigationBarLoading();

    // 隐藏导航栏加载框  
    wx.hideNavigationBarLoading();

    //停止下拉刷新
    wx.stopPullDownRefresh();

  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
    var url = app.getcurrentPage();
    var user_id = wx.getStorageSync('user_id');
    return {
      path: url + "?user_id=" + user_id,
      title: '得道1314'
    };  
  },

  revokeOrder:function(e){

    var that = this;
    var id = e.currentTarget.dataset.orderid;

    var access_token = wx.getStorageSync('access_token');
    wx.request({
      url: api.order.zl_revoke,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        'order_id': id
      },
      success: function () {

        that.getOrderMine();

      }
    });

  },
  // 获取基本信息
  getOrderMine: function () {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    var url = api.order.lesson;
    console.log(access_token);
    console.log(url);
    wx.request({
      url:api.order.lesson,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
      },
      success: function (e) {
        console.log(e);
        console.log(e.data.data.list);
        that.setData({
          list: e.data.data.list
        })
      }
    });
  },
  switchTabs: function (e) {
    // console.log(e.currentTarget.dataset.tap);
    var that = this;
    that.setData({
      nowtab: e.currentTarget.dataset.tap,
    })
  },
})